#include "stdafx.h"
#include "DialogParams.h"
#include <InstanceManagerFuncs.h>

DialogParams::DialogParams(QWidget *parent)
	: QDialog(parent)
{
	ui.setupUi(this);
}

DialogParams::~DialogParams()
{
}

void DialogParams::fillParamsTable(const QString& sheetName, int index)
{
	ui.tableWidget->setRowCount(MAX_PARAM_NUM);
	m_sheetName = sheetName;
	m_index = index;

	for (int i = 0; i < MAX_PARAM_NUM; i++) {
		char szInputValue[256] = { 0 };
		if (GetParamInputValue(sheetName.toLocal8Bit(), index, i, szInputValue)) {
			QString inputValue = QString::fromLocal8Bit(szInputValue);
			ui.tableWidget->setItem(i, 0, new QTableWidgetItem(inputValue));
		}
			
		char szExpectedValue[256] = { 0 };
		if (GetParamExpectedValue(sheetName.toLocal8Bit(), index, i, szExpectedValue)) {
			QString expectedValue = QString::fromLocal8Bit(szExpectedValue);
			ui.tableWidget->setItem(i, 1, new QTableWidgetItem(expectedValue));
		}
	}

	ui.tableWidget->resizeColumnsToContents();
}

void DialogParams::on_btnClose_clicked()
{
	accept();
}

void DialogParams::on_tableWidget_cellChanged(int row, int column)
{
	if (column == 0) {
		if (!SetParamInputValue(m_sheetName.toLocal8Bit(), m_index, row, ui.tableWidget->item(row, column)->text().toLocal8Bit()))
			qDebug() << "setParamInputValue failed!";
	}
	else if (column == 1) {
		if (!SetParamExpectedValue(m_sheetName.toLocal8Bit(), m_index, row, ui.tableWidget->item(row, column)->text().toLocal8Bit()))
			qDebug() << "setParamExpectedValue failed!";
	}
}
